

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../theme.dart';
import '../../../widgets/global_widgets.dart';

Positioned bufferingWidget() {
  return Positioned.fill(
    child: Container(
      color: Colors.black54,
      child: Center(
        child: createCenterLoading(size: 20, color: Colors.white),
      ),
    ),
  );
}

class MiddleSectionWidget extends StatelessWidget {
  final bool isLiveMode;
  final bool isPtzSupported;
  final bool isChatStarted;
  final bool isAudioMuted;
  final bool isVideoCapturing;
  final bool isPtzPanelVisible;
  final bool isSpeedUp;
  final int selectedQualityIndex;
  final Function onChatTap;
  final Function onVolumeTap;
  final Function onQualityTap;
  final Function onCapture;
  final Function onRecordTap;
  final Function onPtzTap;
  final Function onPlaybackSpeedTap;

  const MiddleSectionWidget({
    super.key,
    required this.isLiveMode,
    required this.isSpeedUp,
    required this.isChatStarted,
    required this.isAudioMuted,
    required this.isVideoCapturing,
    required this.selectedQualityIndex,
    required this.isPtzSupported,
    required this.isPtzPanelVisible,
    required this.onChatTap,
    required this.onVolumeTap,
    required this.onQualityTap,
    required this.onCapture,
    required this.onRecordTap,
    required this.onPtzTap,
    required this.onPlaybackSpeedTap,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 100,
      width: double.infinity,
      decoration: const BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          bottomLeft: Radius.circular(30),
          bottomRight: Radius.circular(30),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          // 功能选项 - 语音对讲
          if (isLiveMode) _chatButton(),
          // 功能选项 - 声音
          _volumeButton(),
          // 功能选项 - 视频清晰程度
          if (isLiveMode) _qualityButton(),
          // 功能选项 - 截图
          _shotButton(),
          // 功能选项 - 录像
          _recordButton(),
          // 功能选项 - 操作
          if (isLiveMode && isPtzSupported) _ptzButton(),
          // 功能选项 - 多目摄像头设置
          if (!isLiveMode) _speedButton(),
        ],
      ),
    );
  }

  IconButton _recordButton() {
    return IconButton(
      icon: Icon(Icons.emergency_recording_rounded,
          size: 25, color: isVideoCapturing ? SampleThemeConfigure.colorActive : SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onRecordTap(),
    );
  }

  IconButton _shotButton() {
    return IconButton(
      icon: const Icon(Icons.camera_alt, size: 25, color: SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onCapture(),
    );
  }

  IconButton _speedButton() {
    return IconButton(
      icon: Icon(Icons.speed_rounded, size: 25, color: isSpeedUp ? SampleThemeConfigure.colorActive : SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onPlaybackSpeedTap(),
    );
  }

  IconButton _qualityButton() {
    return IconButton(
      icon: const Icon(Icons.high_quality_rounded, size: 25, color: SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onQualityTap(),
    );
  }

  IconButton _ptzButton() {
    return IconButton(
      icon: Icon(Icons.api_rounded, size: 25, color: isPtzPanelVisible ? SampleThemeConfigure.colorActive : SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onPtzTap(),
    );
  }

  IconButton _volumeButton() {
    return IconButton(
      icon: Icon(isAudioMuted ? Icons.volume_off_rounded : Icons.volume_up_rounded,
          size: 25, color: isAudioMuted ? SampleThemeConfigure.colorTextPrimary : SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onVolumeTap(),
    );
  }

  IconButton _chatButton() {
    return IconButton(
      icon: Icon(isChatStarted ? Icons.mic_rounded : Icons.mic_off_rounded,
          size: 25, color: isChatStarted ? SampleThemeConfigure.colorActive : SampleThemeConfigure.colorTextPrimary),
      onPressed: () => onChatTap(),
    );
  }
}
